package com.lkd.service.impl;

import com.lkd.properties.AliyunProperties;
import com.lkd.service.FileUploadService;
import com.lkd.utils.AliyunOSSUtils;
import com.lkd.utils.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;


@Service
public class FileUploadServiceImpl implements FileUploadService {
    @Autowired
    AliyunProperties aliyunProperties;
    @Override
    public void upload(MultipartFile image) throws Exception {
        //获取图片原始文件名
        String oname = image.getOriginalFilename();

        //创建新的文件名字
        String newName = UUID.fastUUID().toString()+oname.substring(oname.lastIndexOf("."));

        //上传至阿里云
        AliyunOSSUtils.upload(aliyunProperties.getEndpoint(),aliyunProperties.getBucketName(),image.getBytes(),newName);
    }
}
